const receptionBill = require("../database/model-reception");
const receptionBillDraft = require("../database/model-reception-draft");

const BillDelete = async (ctx) => {
  const { billId, isDraft } = ctx.request.query;
  if (!billId) {
    const err = new Error("billId缺失");
    err.status = 400;
    throw err;
  }
  if (isDraft === "1") {
    await receptionBillDraft.destroy({
      where: {
        id: billId,
      },
      force: true,
    });
  } else {
    // 非草稿不可删除
    return ctx.fail({
      msg: "单据不可删除！",
    });
    // await receptionBill.destroy({
    //   where: {
    //     id: billId,
    //   },
    //   force: true,
    // });
  }

  ctx.success({
    msg: "单据已删除！",
  });
};
BillDelete.method = "get";
BillDelete.query = {
  billId: "string",
  "isDraft?": "0|1",
};
BillDelete.mark = "单据列表";
module.exports = BillDelete;
